package com.itstyle.quartz.job;

import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.util.StopWatch;

import javax.annotation.Resource;
import java.io.Serializable;
import java.text.SimpleDateFormat;
import java.util.Date;

public class RocketMQProducerJob implements Job,Serializable {

    private static final long serialVersionUID = -1183120196085339829L;

    private static final Logger log = LoggerFactory.getLogger(RocketMQProducerJob.class);

    @Resource
    private RocketMQProducer rocketMQProducer;

    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        StopWatch stopWatch = new StopWatch();
        stopWatch.start();


        Date date=new Date();
        SimpleDateFormat df=new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");//设置日期时间格式

        rocketMQProducer.sendMessage("Hello RocketMQ " + df.format(date), "TopicTest",
                "TagTest", "Key" + System.currentTimeMillis());

        stopWatch.stop();
        log.info("RocketMQProducer发送消息耗时: " + stopWatch.getTotalTimeMillis()+"毫秒");
    }
}